import { Component, OnInit } from '@angular/core';
import { ApiService } from '../api/api.service';
import { ApiUrl } from '../api/ApiUrl';
import { ConnectVO } from '../vo/ConnectVO';
import { UserVO } from '../vo/UserVO';
@Component({
  selector: 'app-connect',
  templateUrl: './connect.page.html',
  styleUrls: ['./connect.page.scss'],
})
export class ConnectPage implements OnInit {
  items: ConnectVO[] = [];
  userItem: UserVO;
  constructor(public api: ApiService) { }

  ngOnInit() {
    this.userItem = ApiUrl.user;
    this.onSearch('0');
  }
  onSearch(iid: string = '0') {
    this.api.getItems<ConnectVO>(ApiUrl.getConnect, { 'iid': iid, 'iorgname': this.userItem.iorgname }).subscribe(response => {

      if (response === null || response.length === 0) {
        console.log('没有数据返回');
        return;
      }
      this.items = response;
     for (let i = 0; i < this.items.length; i++) {
       if (this.items[i].ccpmpanypic === null || this.items[i].ccpmpanypic === '') {
        this.items[i].ccpmpanypic = 'assets/image/qiye.png';
       } else {
        this.items[i].ccpmpanypic = ApiUrl.companyUrl + this.items[i].ccpmpanypic;
       }

       if (this.items[i].cbankpic === null || this.items[i].cbankpic === '') {
        this.items[i].cbankpic = 'assets/image/bank.png';
       } else {
        this.items[i].cbankpic = ApiUrl.bankUrl + this.items[i].cbankpic;
       }
     }
    }, () => {

      console.log('出错了');
    });
  }
  doUpRefresh(evt) {
    console.log('上拉刷新');
    this.onSearch(this.items[this.items.length - 1].iid);
  }


}
